/**
 *   For
 *   Created by xs at 2018/1/12
 */
"use strict";
(function () {
    angular.module('app')
        .factory('userService',fn);

    function fn($cookies) {
        var self = {};
        self.profile = {};
        self.isAdmin = false;
        self.username = $cookies.get('username') || '';
        self.isConsultant = $cookies.get('isConsultant')==='true';
        self.consultantId = $cookies.get('consultantId') || '';
        self.asset = $cookies.get('asset') || 0;

        self.setUser = function (profile) {
            var username = profile['username'];
            var isConsultant = profile['isConsultant'];
            var asset = profile['asset'];
            self.username = username;
            self.asset = asset;
            self.isConsultant = isConsultant;
            if (isConsultant) {
                self.consultantId = username;
                $cookies.put('consultantId', username);
            }
            self.profile = profile;
            $cookies.put('username', username);
            $cookies.put('isConsultant', isConsultant);
            $cookies.put('asset', asset);
            //console.log($cookies.get('username'),$cookies.get('isConsultant'))
        };
        self.removeUser = function(){
            $cookies.remove('username');
            $cookies.remove('isConsultant');
            $cookies.remove('consultantId');
            console.log('remove',$cookies.get('username'),$cookies.get('isConsultant'));
        };

        return self;
    }
})();